package com.dmx.cep.dao.impl;

import java.util.List;

import com.dmx.cep.dao.UserInfoDao;
import com.dmx.cep.entity.UserInfo;
import com.dmx.fw.dao.hibernateimpl.BaseDaoImpl;

public class UserInfoDaoImpl extends BaseDaoImpl implements UserInfoDao {

    public void batchDeleteUserInfoByIds(String[] ids){
    	if(ids==null){
    		throw new IllegalArgumentException("arg ids couldn't be null for UserInfoDaoImpl.batchDeleteUserInfoByIds");
    	}
        if (ids != null) {
            for(String id:ids){
               deleteUserInfoById(id);
            }
        }
    }

    public void deleteUserInfoById(String id){
    	UserInfo userInfo =findUserInfoById(id);
    	if(userInfo!=null)
    		super.getHibernateTemplate().delete(userInfo);
    }

    public void saveOrUpdateUserInfo(UserInfo UserInfo){
        super.getHibernateTemplate().saveOrUpdate(UserInfo);
    }

    @SuppressWarnings("unchecked")
	public UserInfo findUserInfoById(String id){
    	if(id==null||"".equals(id)){
    		throw new IllegalArgumentException("arg id couldn't be null for UserInfoDaoImpl.deleteUserInfoById");
    	}
        String hql = "from UserInfo where uid =?";
        List<UserInfo> userInfos = this.getHibernateTemplate().find(hql,id);
        if(!userInfos.isEmpty())
          return userInfos.get(0);
        return null;
    }



	
	
}
